package edu.sctu.xiangkun.day201506.day20150605.TextTwo;

import java.text.DateFormat;
import java.util.Calendar;

/**
 * Created by lenovo on 2015/6/5.
 */
public class CalendarClass {

Calendar calendar = Calendar.getInstance();

    public void getCalendar(){
        System.out.println("时间："+calendar.getTime());

        int year = calendar.get(calendar.YEAR);

        int month = calendar.get(calendar.MONTH)+1;

        int day = calendar.get(calendar.DAY_OF_MONTH);

        int date = calendar.get(calendar.DATE);

        int hour = calendar.get(calendar.HOUR_OF_DAY);

        int minute = calendar.get(calendar.MINUTE);

        int second = calendar.get(calendar.SECOND);

        int week = calendar.get(calendar.DAY_OF_WEEK)-1;

        System.out.println("时间："+year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second);
        System.out.println("时间："+year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second);
        System.out.println("星期："+week);
    }

    public void setDate(){
        int month = calendar.get(calendar.MONTH)+1;
        int date = calendar.get(calendar.DATE);
        System.out.println("日期："+month+"月"+date + "日");

        int month1 = calendar.get(calendar.MONTH)+1;
        calendar.get(calendar.DATE);
        calendar.add(calendar.DATE, 2);
        System.out.println("修改日期："+month1+"月"+calendar.get(calendar.DATE) + "日");

        calendar.set(2015,6,11);
        int year = calendar.get(calendar.YEAR);
        int month2 = calendar.get(calendar.MONTH);
        int date1 = calendar.get(calendar.DATE);
        System.out.println("周年纪念日:"+year+"-"+month2+"-"+date1);


        calendar.set(calendar.MONTH,8);
        calendar.set(calendar.DAY_OF_MONTH,25);
        int month3 = calendar.get(calendar.MONTH);
        int day1 = calendar.get(calendar.DAY_OF_MONTH);
        System.out.println("你的生日："+month3+"月"+day1+"日");

    }

    public void setDateAndTime(){
        calendar.set(2013,6,11,9,30,10);
        int year = calendar.get(calendar.YEAR);
        int month = calendar.get(calendar.MONTH);
        int day = calendar.get(calendar.DAY_OF_MONTH);
        int hour = calendar.get(calendar.HOUR);
        int minute = calendar.get(calendar.MINUTE);
        int second = calendar.get(calendar.SECOND);
        System.out.println("我们相识于"+year+"年"+month+"月"+day+"日"+hour+"点"+minute+"分"+second+"秒");

    }

    public void getDateFormat(){
        DateFormat dateFormat = DateFormat.getDateInstance(10);
        int str = dateFormat.DEFAULT;
        System.out.println("日期："+str);
        System.out.println("日期："+dateFormat.format(calendar.getTime()));
    }
}
